from django.template.library import Library
from django.conf import settings
from copy import deepcopy

register = Library()


@register.inclusion_tag('index/main_menus.html')
def show_menu(request):
    menus = deepcopy(settings.MENUS[request.user.role])
    current_url = request.path_info
    for menu in menus:
        for ch in menu['children']:
            if ch['url'] == current_url:
                ch['class'] = 'active'
    return {'user_menus': menus}
